package com.LeeCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 删除子文件夹
 */

public class Code1233 {
    public static void main(String[] args) {
        String[] folder = {"/a", "/a/b", "/c/d", "/c/d/e", "/c/f"};
        System.out.println(new Code1233().removeSubfolders(folder));
    }

    public List<String> removeSubfolders(String[] folder) {
        Arrays.sort(folder);

        List<String> ans = new ArrayList<>();
        String prev = "";
        for (String path : folder) {
            if (prev.isEmpty() || !path.startsWith(prev + "/")) {
                ans.add(path);
                prev = path;
            }
        }
        return ans;
    }
}
